<?php
	set_time_limit(36000);
	error_reporting(E_ALL);
	require_once("lista_tablas.php");
	$host = "localhost:C:/ARCHIVOS DE PROGRAMA/IBDADOS/BDADOS.GDB";

	$dbh = ibase_connect($host, 'SYSDBA', 'masterkey', 'ISO8859_1', '100', '1' ) ;
	
	$link = mysql_connect('localhost', 'root', 'mate');
	$db_selected = mysql_select_db('nutri_db', $link);
		
	for($indice=0; $indice<count($arrTablas); $indice++){
		$tabla = $arrTablas[$indice];
	
		$stmt = 'SELECT * FROM '.$tabla;
		$sth = ibase_query($dbh, $stmt);
	
	
		while ($row = ibase_fetch_assoc($sth)) {
			
			//Estructura
			$query  = "INSERT INTO `".$tabla."` ";
			$query .= "(";
			$coma = "";
			foreach($row as $name=>$value){
				$query .= $coma."`".$name."`";
				$coma = ", ";
			}
			$query .= ") VALUES ";
			
			
			//Datos
			$coma = "";
			$query .= "(";
			foreach($row as $name=>$value){
				if($value != ''){
					$value = "'".addslashes($value)."'";
				}else{
					$value = "NULL";
				}
				$query .= $coma.$value;
				$coma = ", ";
			}
			$query .= ");";
			
			//echo $query;
			
			mysql_query($query);
			if(mysql_errno() > 0){
				echo $query;
				echo mysql_error();
				die();
			}
		}
	
	}
	
	ibase_free_result($sth);
	ibase_close($dbh);
	
	
    // get server version and implementation strings
    /*if (($service = ibase_service_attach('localhost', 'sysdba', 'masterkey')) != FALSE) {
        $server_info  = ibase_server_info($service, IBASE_SVC_SERVER_VERSION)
                      . ' / '
                      . ibase_server_info($service, IBASE_SVC_IMPLEMENTATION);
        ibase_service_detach($service);
    }
    else {
        $ib_error = ibase_errmsg();
    }
	echo $server_info;  */
?>
